package com.wzu.controller;

import com.wzu.entity.Payment;
import com.wzu.entity.Result;
import com.wzu.service.PaymentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;

@RestController
@RequestMapping("/payment")
@CrossOrigin
public class PaymentController {
    @Autowired
    private PaymentService paymentService;

    // 多条件查询
    @GetMapping("/list")
    public Result list(@RequestParam(required = false) String insuredName,
                      @RequestParam(required = false) String cardId) {
        List<Payment> list = paymentService.searchPayment(insuredName, cardId);
        return new Result("查询成功", list, 200);
    }

    // 添加
    @PostMapping("/add")
    public Result add(@RequestBody Payment payment) {
        if (paymentService.addPayment(payment)) {
            return new Result("添加成功", null, 200);
        } else {
            return new Result("添加失败", null, 400);
        }
    }

    // 更新
    @PutMapping("/update")
    public Result update(@RequestBody Payment payment) {
        if (paymentService.updatePayment(payment)) {
            return new Result("更新成功", null, 200);
        } else {
            return new Result("更新失败", null, 400);
        }
    }

    // 删除
    @DeleteMapping("/delete/{id}")
    public Result delete(@PathVariable Long id) {
        if (paymentService.deletePayment(id)) {
            return new Result("删除成功", null, 200);
        } else {
            return new Result("删除失败", null, 400);
        }
    }
} 